// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyWellBoreAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <visit-config.h>
#include <PyColorControlPointList.h>
#include <ColorAttribute.h>
#include <PyColorAttributeList.h>

// ****************************************************************************
// Module: PyWellBoreAttributes
//
// Purpose:
//   This class contains the plot attributes for the well bore plot.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a WellBoreAttributes.
//
struct WellBoreAttributesObject
{
    PyObject_HEAD
    WellBoreAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewWellBoreAttributes(int);
std::string
PyWellBoreAttributes_ToString(const WellBoreAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    { // new scope
        std::string objPrefix(prefix);
        objPrefix += "defaultPalette.";
        str += PyColorControlPointList_ToString(&atts->GetDefaultPalette(), objPrefix.c_str(), forLogging);
    }
    {   const unsignedCharVector &changedColors = atts->GetChangedColors();
        snprintf(tmpStr, 1000, "%schangedColors = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < changedColors.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", int(changedColors[i]));
            str += tmpStr;
            if(i < changedColors.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    const char *colorType_names = "ColorBySingleColor, ColorByMultipleColors, ColorByColorTable";
    switch (atts->GetColorType())
    {
      case WellBoreAttributes::ColorBySingleColor:
          snprintf(tmpStr, 1000, "%scolorType = %sColorBySingleColor  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::ColorByMultipleColors:
          snprintf(tmpStr, 1000, "%scolorType = %sColorByMultipleColors  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::ColorByColorTable:
          snprintf(tmpStr, 1000, "%scolorType = %sColorByColorTable  # %s\n", prefix, prefix, colorType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%scolorTableName = \"%s\"\n", prefix, atts->GetColorTableName().c_str());
    str += tmpStr;
    if(atts->GetInvertColorTable())
        snprintf(tmpStr, 1000, "%sinvertColorTable = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sinvertColorTable = 0\n", prefix);
    str += tmpStr;
    const unsigned char *singleColor = atts->GetSingleColor().GetColor();
    snprintf(tmpStr, 1000, "%ssingleColor = (%d, %d, %d, %d)\n", prefix, int(singleColor[0]), int(singleColor[1]), int(singleColor[2]), int(singleColor[3]));
    str += tmpStr;
    { const ColorAttributeList &cL = atts->GetMultiColor();
        const char *comment = (prefix==0 || strcmp(prefix,"")==0) ? "# " : "";
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL[i].GetColor();
            snprintf(tmpStr, 1000, "%s%sSetMultiColor(%d, (%d, %d, %d, %d))\n",
                     comment, prefix, i, int(c[0]), int(c[1]), int(c[2]), int(c[3]));
            str += tmpStr;
        }
    }
    const char *drawWellsAs_names = "Lines, Cylinders";
    switch (atts->GetDrawWellsAs())
    {
      case WellBoreAttributes::Lines:
          snprintf(tmpStr, 1000, "%sdrawWellsAs = %sLines  # %s\n", prefix, prefix, drawWellsAs_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::Cylinders:
          snprintf(tmpStr, 1000, "%sdrawWellsAs = %sCylinders  # %s\n", prefix, prefix, drawWellsAs_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    const char *wellCylinderQuality_names = "Low, Medium, High, Super";
    switch (atts->GetWellCylinderQuality())
    {
      case WellBoreAttributes::Low:
          snprintf(tmpStr, 1000, "%swellCylinderQuality = %sLow  # %s\n", prefix, prefix, wellCylinderQuality_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::Medium:
          snprintf(tmpStr, 1000, "%swellCylinderQuality = %sMedium  # %s\n", prefix, prefix, wellCylinderQuality_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::High:
          snprintf(tmpStr, 1000, "%swellCylinderQuality = %sHigh  # %s\n", prefix, prefix, wellCylinderQuality_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::Super:
          snprintf(tmpStr, 1000, "%swellCylinderQuality = %sSuper  # %s\n", prefix, prefix, wellCylinderQuality_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%swellRadius = %g\n", prefix, atts->GetWellRadius());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%swellLineWidth = %d\n", prefix, atts->GetWellLineWidth());
    str += tmpStr;
    const char *wellAnnotation_names = "NONE, StemOnly, NameOnly, StemAndName";
    switch (atts->GetWellAnnotation())
    {
      case WellBoreAttributes::None:
          snprintf(tmpStr, 1000, "%swellAnnotation = %sNONE  # %s\n", prefix, prefix, wellAnnotation_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::StemOnly:
          snprintf(tmpStr, 1000, "%swellAnnotation = %sStemOnly  # %s\n", prefix, prefix, wellAnnotation_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::NameOnly:
          snprintf(tmpStr, 1000, "%swellAnnotation = %sNameOnly  # %s\n", prefix, prefix, wellAnnotation_names);
          str += tmpStr;
          break;
      case WellBoreAttributes::StemAndName:
          snprintf(tmpStr, 1000, "%swellAnnotation = %sStemAndName  # %s\n", prefix, prefix, wellAnnotation_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%swellStemHeight = %g\n", prefix, atts->GetWellStemHeight());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%swellNameScale = %g\n", prefix, atts->GetWellNameScale());
    str += tmpStr;
    if(atts->GetLegendFlag())
        snprintf(tmpStr, 1000, "%slegendFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%slegendFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%snWellBores = %d\n", prefix, atts->GetNWellBores());
    str += tmpStr;
    {   const intVector &wellBores = atts->GetWellBores();
        snprintf(tmpStr, 1000, "%swellBores = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < wellBores.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", wellBores[i]);
            str += tmpStr;
            if(i < wellBores.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &wellNames = atts->GetWellNames();
        snprintf(tmpStr, 1000, "%swellNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < wellNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", wellNames[i].c_str());
            str += tmpStr;
            if(i < wellNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
WellBoreAttributes_Notify(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_SetDefaultPalette(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *newValue = NULL;
    if(!PyArg_ParseTuple(args, "O", &newValue))
        return NULL;
    if(!PyColorControlPointList_Check(newValue))
        return PyErr_Format(PyExc_TypeError, "Field defaultPalette can be set only with ColorControlPointList objects");

    obj->data->SetDefaultPalette(*PyColorControlPointList_FromPyObject(newValue));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetDefaultPalette(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    // Since the new object will point to data owned by this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyColorControlPointList_Wrap(&obj->data->GetDefaultPalette());
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyColorControlPointList_SetParent(retval, self);

    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetChangedColors(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    typedef unsigned char uchar;
    ucharVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        uchar cval = uchar(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ uchar");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ uchar");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            uchar cval = uchar(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more uchars");

    obj->data->GetChangedColors() = vec;
    // Mark the changedColors in the object as modified.
    obj->data->SelectChangedColors();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetChangedColors(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the changedColors.
    const unsignedCharVector &changedColors = obj->data->GetChangedColors();
    PyObject *retval = PyTuple_New(changedColors.size());
    for(size_t i = 0; i < changedColors.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(changedColors[i])));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetColorType(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid colorType value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " ColorBySingleColor";
        ss << ", ColorByMultipleColors";
        ss << ", ColorByColorTable";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the colorType in the object.
    obj->data->SetColorType(WellBoreAttributes::ColoringMethod(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetColorType(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetColorType()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetColorTableName(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the colorTableName in the object.
    obj->data->SetColorTableName(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetColorTableName(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetColorTableName().c_str());
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetInvertColorTable(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the invertColorTable in the object.
    obj->data->SetInvertColorTable(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetInvertColorTable(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetInvertColorTable()?1L:0L);
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetSingleColor(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the singleColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetSingleColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetSingleColor(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the singleColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *singleColor = obj->data->GetSingleColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(singleColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(singleColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(singleColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(singleColor[3])));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetMultiColor(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *pyobj = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();
    int index = 0;
    int c[4] = {0,0,0,255};
    bool setTheColor = true;

    if(!PyArg_ParseTuple(args, "iiiii", &index, &c[0], &c[1], &c[2], &c[3]))
    {
        if(!PyArg_ParseTuple(args, "iiii", &index, &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "idddd", &index, &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "iddd", &index, &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                if(!PyArg_ParseTuple(args, "iO", &index, &pyobj))
                {
                    if(PyArg_ParseTuple(args, "O", &pyobj))
                    {
                        setTheColor = false;
                        if(PyTuple_Check(pyobj))
                        {
                            // Make sure that the tuple is the right size.
                            if(PyTuple_Size(pyobj) < cL.GetNumColors())
                                return PyErr_Format(PyExc_IndexError, "color tuple size=%d, expected=%d", (int) PyTuple_Size(pyobj), (int) cL.GetNumColors());

                            // Make sure that the tuple is the right size.
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyTuple_Size(pyobj); ++i)
                            {
                                PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item); ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                        {
                                           delete [] C;
                                           return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d at index %d as a color component",j,i);
                                        }
                                    }
                                }
                                else
                                {
                                    delete [] C;
                                    return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");
                                }
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);
                            delete [] C;
                        }
                        else if(PyList_Check(pyobj))
                        {
                            // Make sure that the list is the right size.
                            if(PyList_Size(pyobj) < cL.GetNumColors())
                                return PyErr_Format(PyExc_IndexError, "color tuple size=%d, expected=%d", (int) PyTuple_Size(pyobj), (int) cL.GetNumColors());

                            // Make sure that the tuple is the right size.
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyList_Size(pyobj); ++i)
                            {
                                PyObject *item = PyList_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item); ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                        {
                                           delete [] C;
                                           return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d at index %d as a color component",j,i);
                                        }
                                    }
                                }
                                else
                                {
                                    delete [] C;
                                    return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");
                                }
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);

                            delete [] C;
                        }
                        else
                            return PyErr_Format(PyExc_TypeError, "Expecting tuple or list");
                    }
                }
                else
                {
                    if(!PyTuple_Check(pyobj))
                        return NULL;

                    // Make sure that the tuple is the right size.
                    if(PyTuple_Size(pyobj) < 3 || PyTuple_Size(pyobj) > 4)
                        return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");

                    // Make sure that all elements in the tuple are ints.
                    for(int i = 0; i < PyTuple_Size(pyobj); ++i)
                    {
                        PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                        if(PyInt_Check(item))
                            c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(pyobj, i)));
                        else if(PyFloat_Check(item))
                            c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(pyobj, i)));
                        else
                            return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d as a color component", i);
                    }
                }
            }
        }
        PyErr_Clear();
    }

    if(index < 0 || index >= cL.GetNumColors())
        return PyErr_Format(PyExc_ValueError, "color index out of range 0 <= i < %d", (int) cL.GetNumColors());

    // Set the color in the object.
    if(setTheColor)
        cL[index] = ColorAttribute(c[0], c[1], c[2], c[3]);
    cL.SelectColors();
    obj->data->SelectMultiColor();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetMultiColor(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();

    int index = 0;
    if(PyArg_ParseTuple(args, "i", &index))
    {
        if(index < 0 || index >= cL.GetNumColors())
            return NULL;

        // Allocate a tuple the with enough entries to hold the singleColor.
        retval = PyTuple_New(4);
        const unsigned char *c = cL.GetColors(index).GetColor();
        PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(c[0])));
        PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(c[1])));
        PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(c[2])));
        PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(c[3])));
    }
    else
    {
        PyErr_Clear();

        // Return the whole thing.
        retval = PyList_New(cL.GetNumColors());
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL.GetColors(i).GetColor();

            PyObject *t = PyTuple_New(4);
            PyTuple_SET_ITEM(t, 0, PyInt_FromLong(long(c[0])));
            PyTuple_SET_ITEM(t, 1, PyInt_FromLong(long(c[1])));
            PyTuple_SET_ITEM(t, 2, PyInt_FromLong(long(c[2])));
            PyTuple_SET_ITEM(t, 3, PyInt_FromLong(long(c[3])));

            PyList_SET_ITEM(retval, i, t);
        }
    }
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetDrawWellsAs(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid drawWellsAs value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Lines";
        ss << ", Cylinders";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the drawWellsAs in the object.
    obj->data->SetDrawWellsAs(WellBoreAttributes::WellRenderingMode(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetDrawWellsAs(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetDrawWellsAs()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellCylinderQuality(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 4)
    {
        std::stringstream ss;
        ss << "An invalid wellCylinderQuality value was given." << std::endl;
        ss << "Valid values are in the range [0,3]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Low";
        ss << ", Medium";
        ss << ", High";
        ss << ", Super";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the wellCylinderQuality in the object.
    obj->data->SetWellCylinderQuality(WellBoreAttributes::DetailLevel(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellCylinderQuality(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetWellCylinderQuality()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellRadius(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    float cval = float(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ float");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ float");
    }

    Py_XDECREF(packaged_args);

    // Set the wellRadius in the object.
    obj->data->SetWellRadius(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellRadius(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetWellRadius()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellLineWidth(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the wellLineWidth in the object.
    obj->data->SetWellLineWidth(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellLineWidth(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetWellLineWidth()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellAnnotation(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 4)
    {
        std::stringstream ss;
        ss << "An invalid wellAnnotation value was given." << std::endl;
        ss << "Valid values are in the range [0,3]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", StemOnly";
        ss << ", NameOnly";
        ss << ", StemAndName";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the wellAnnotation in the object.
    obj->data->SetWellAnnotation(WellBoreAttributes::WellAnnotation(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellAnnotation(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetWellAnnotation()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellStemHeight(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    float cval = float(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ float");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ float");
    }

    Py_XDECREF(packaged_args);

    // Set the wellStemHeight in the object.
    obj->data->SetWellStemHeight(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellStemHeight(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetWellStemHeight()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellNameScale(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    float cval = float(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ float");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ float");
    }

    Py_XDECREF(packaged_args);

    // Set the wellNameScale in the object.
    obj->data->SetWellNameScale(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellNameScale(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetWellNameScale()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetLegendFlag(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the legendFlag in the object.
    obj->data->SetLegendFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetLegendFlag(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLegendFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetNWellBores(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the nWellBores in the object.
    obj->data->SetNWellBores(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetNWellBores(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetNWellBores()));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellBores(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetWellBores() = vec;
    // Mark the wellBores in the object as modified.
    obj->data->SelectWellBores();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellBores(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the wellBores.
    const intVector &wellBores = obj->data->GetWellBores();
    PyObject *retval = PyTuple_New(wellBores.size());
    for(size_t i = 0; i < wellBores.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(wellBores[i])));
    return retval;
}

/*static*/ PyObject *
WellBoreAttributes_SetWellNames(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetWellNames() = vec;
    // Mark the wellNames in the object as modified.
    obj->data->SelectWellNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
WellBoreAttributes_GetWellNames(PyObject *self, PyObject *args)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the wellNames.
    const stringVector &wellNames = obj->data->GetWellNames();
    PyObject *retval = PyTuple_New(wellNames.size());
    for(size_t i = 0; i < wellNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(wellNames[i].c_str()));
    return retval;
}



PyMethodDef PyWellBoreAttributes_methods[WELLBOREATTRIBUTES_NMETH] = {
    {"Notify", WellBoreAttributes_Notify, METH_VARARGS},
    {"SetDefaultPalette", WellBoreAttributes_SetDefaultPalette, METH_VARARGS},
    {"GetDefaultPalette", WellBoreAttributes_GetDefaultPalette, METH_VARARGS},
    {"SetChangedColors", WellBoreAttributes_SetChangedColors, METH_VARARGS},
    {"GetChangedColors", WellBoreAttributes_GetChangedColors, METH_VARARGS},
    {"SetColorType", WellBoreAttributes_SetColorType, METH_VARARGS},
    {"GetColorType", WellBoreAttributes_GetColorType, METH_VARARGS},
    {"SetColorTableName", WellBoreAttributes_SetColorTableName, METH_VARARGS},
    {"GetColorTableName", WellBoreAttributes_GetColorTableName, METH_VARARGS},
    {"SetInvertColorTable", WellBoreAttributes_SetInvertColorTable, METH_VARARGS},
    {"GetInvertColorTable", WellBoreAttributes_GetInvertColorTable, METH_VARARGS},
    {"SetSingleColor", WellBoreAttributes_SetSingleColor, METH_VARARGS},
    {"GetSingleColor", WellBoreAttributes_GetSingleColor, METH_VARARGS},
    {"SetMultiColor", WellBoreAttributes_SetMultiColor, METH_VARARGS},
    {"GetMultiColor", WellBoreAttributes_GetMultiColor, METH_VARARGS},
    {"SetDrawWellsAs", WellBoreAttributes_SetDrawWellsAs, METH_VARARGS},
    {"GetDrawWellsAs", WellBoreAttributes_GetDrawWellsAs, METH_VARARGS},
    {"SetWellCylinderQuality", WellBoreAttributes_SetWellCylinderQuality, METH_VARARGS},
    {"GetWellCylinderQuality", WellBoreAttributes_GetWellCylinderQuality, METH_VARARGS},
    {"SetWellRadius", WellBoreAttributes_SetWellRadius, METH_VARARGS},
    {"GetWellRadius", WellBoreAttributes_GetWellRadius, METH_VARARGS},
    {"SetWellLineWidth", WellBoreAttributes_SetWellLineWidth, METH_VARARGS},
    {"GetWellLineWidth", WellBoreAttributes_GetWellLineWidth, METH_VARARGS},
    {"SetWellAnnotation", WellBoreAttributes_SetWellAnnotation, METH_VARARGS},
    {"GetWellAnnotation", WellBoreAttributes_GetWellAnnotation, METH_VARARGS},
    {"SetWellStemHeight", WellBoreAttributes_SetWellStemHeight, METH_VARARGS},
    {"GetWellStemHeight", WellBoreAttributes_GetWellStemHeight, METH_VARARGS},
    {"SetWellNameScale", WellBoreAttributes_SetWellNameScale, METH_VARARGS},
    {"GetWellNameScale", WellBoreAttributes_GetWellNameScale, METH_VARARGS},
    {"SetLegendFlag", WellBoreAttributes_SetLegendFlag, METH_VARARGS},
    {"GetLegendFlag", WellBoreAttributes_GetLegendFlag, METH_VARARGS},
    {"SetNWellBores", WellBoreAttributes_SetNWellBores, METH_VARARGS},
    {"GetNWellBores", WellBoreAttributes_GetNWellBores, METH_VARARGS},
    {"SetWellBores", WellBoreAttributes_SetWellBores, METH_VARARGS},
    {"GetWellBores", WellBoreAttributes_GetWellBores, METH_VARARGS},
    {"SetWellNames", WellBoreAttributes_SetWellNames, METH_VARARGS},
    {"GetWellNames", WellBoreAttributes_GetWellNames, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
WellBoreAttributes_dealloc(PyObject *v)
{
   WellBoreAttributesObject *obj = (WellBoreAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *WellBoreAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyWellBoreAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "defaultPalette") == 0)
        return WellBoreAttributes_GetDefaultPalette(self, NULL);
    if(strcmp(name, "changedColors") == 0)
        return WellBoreAttributes_GetChangedColors(self, NULL);
    if(strcmp(name, "colorType") == 0)
        return WellBoreAttributes_GetColorType(self, NULL);
    if(strcmp(name, "ColorBySingleColor") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::ColorBySingleColor));
    if(strcmp(name, "ColorByMultipleColors") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::ColorByMultipleColors));
    if(strcmp(name, "ColorByColorTable") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::ColorByColorTable));

    if(strcmp(name, "colorTableName") == 0)
        return WellBoreAttributes_GetColorTableName(self, NULL);
    if(strcmp(name, "invertColorTable") == 0)
        return WellBoreAttributes_GetInvertColorTable(self, NULL);
    if(strcmp(name, "singleColor") == 0)
        return WellBoreAttributes_GetSingleColor(self, NULL);
    if(strcmp(name, "multiColor") == 0)
        return WellBoreAttributes_GetMultiColor(self, NULL);
    if(strcmp(name, "drawWellsAs") == 0)
        return WellBoreAttributes_GetDrawWellsAs(self, NULL);
    if(strcmp(name, "Lines") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::Lines));
    if(strcmp(name, "Cylinders") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::Cylinders));

    if(strcmp(name, "wellCylinderQuality") == 0)
        return WellBoreAttributes_GetWellCylinderQuality(self, NULL);
    if(strcmp(name, "Low") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::Low));
    if(strcmp(name, "Medium") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::Medium));
    if(strcmp(name, "High") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::High));
    if(strcmp(name, "Super") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::Super));

    if(strcmp(name, "wellRadius") == 0)
        return WellBoreAttributes_GetWellRadius(self, NULL);
    if(strcmp(name, "wellLineWidth") == 0)
        return WellBoreAttributes_GetWellLineWidth(self, NULL);
    if(strcmp(name, "wellAnnotation") == 0)
        return WellBoreAttributes_GetWellAnnotation(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::None));
    if(strcmp(name, "StemOnly") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::StemOnly));
    if(strcmp(name, "NameOnly") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::NameOnly));
    if(strcmp(name, "StemAndName") == 0)
        return PyInt_FromLong(long(WellBoreAttributes::StemAndName));

    if(strcmp(name, "wellStemHeight") == 0)
        return WellBoreAttributes_GetWellStemHeight(self, NULL);
    if(strcmp(name, "wellNameScale") == 0)
        return WellBoreAttributes_GetWellNameScale(self, NULL);
    if(strcmp(name, "legendFlag") == 0)
        return WellBoreAttributes_GetLegendFlag(self, NULL);
    if(strcmp(name, "nWellBores") == 0)
        return WellBoreAttributes_GetNWellBores(self, NULL);
    if(strcmp(name, "wellBores") == 0)
        return WellBoreAttributes_GetWellBores(self, NULL);
    if(strcmp(name, "wellNames") == 0)
        return WellBoreAttributes_GetWellNames(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyWellBoreAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyWellBoreAttributes_methods[i].ml_name),
                PyString_FromString(PyWellBoreAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyWellBoreAttributes_methods, self, name);
}

int
PyWellBoreAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "defaultPalette") == 0)
        obj = WellBoreAttributes_SetDefaultPalette(self, args);
    else if(strcmp(name, "changedColors") == 0)
        obj = WellBoreAttributes_SetChangedColors(self, args);
    else if(strcmp(name, "colorType") == 0)
        obj = WellBoreAttributes_SetColorType(self, args);
    else if(strcmp(name, "colorTableName") == 0)
        obj = WellBoreAttributes_SetColorTableName(self, args);
    else if(strcmp(name, "invertColorTable") == 0)
        obj = WellBoreAttributes_SetInvertColorTable(self, args);
    else if(strcmp(name, "singleColor") == 0)
        obj = WellBoreAttributes_SetSingleColor(self, args);
    else if(strcmp(name, "multiColor") == 0)
        obj = WellBoreAttributes_SetMultiColor(self, args);
    else if(strcmp(name, "drawWellsAs") == 0)
        obj = WellBoreAttributes_SetDrawWellsAs(self, args);
    else if(strcmp(name, "wellCylinderQuality") == 0)
        obj = WellBoreAttributes_SetWellCylinderQuality(self, args);
    else if(strcmp(name, "wellRadius") == 0)
        obj = WellBoreAttributes_SetWellRadius(self, args);
    else if(strcmp(name, "wellLineWidth") == 0)
        obj = WellBoreAttributes_SetWellLineWidth(self, args);
    else if(strcmp(name, "wellAnnotation") == 0)
        obj = WellBoreAttributes_SetWellAnnotation(self, args);
    else if(strcmp(name, "wellStemHeight") == 0)
        obj = WellBoreAttributes_SetWellStemHeight(self, args);
    else if(strcmp(name, "wellNameScale") == 0)
        obj = WellBoreAttributes_SetWellNameScale(self, args);
    else if(strcmp(name, "legendFlag") == 0)
        obj = WellBoreAttributes_SetLegendFlag(self, args);
    else if(strcmp(name, "nWellBores") == 0)
        obj = WellBoreAttributes_SetNWellBores(self, args);
    else if(strcmp(name, "wellBores") == 0)
        obj = WellBoreAttributes_SetWellBores(self, args);
    else if(strcmp(name, "wellNames") == 0)
        obj = WellBoreAttributes_SetWellNames(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
WellBoreAttributes_print(PyObject *v, FILE *fp, int flags)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)v;
    fprintf(fp, "%s", PyWellBoreAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
WellBoreAttributes_str(PyObject *v)
{
    WellBoreAttributesObject *obj = (WellBoreAttributesObject *)v;
    return PyString_FromString(PyWellBoreAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *WellBoreAttributes_Purpose = "This class contains the plot attributes for the well bore plot.";
#else
static char *WellBoreAttributes_Purpose = "This class contains the plot attributes for the well bore plot.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(WellBoreAttributesType,         \
                  "WellBoreAttributes",           \
                  WellBoreAttributesObject,       \
                  WellBoreAttributes_dealloc,     \
                  WellBoreAttributes_print,       \
                  PyWellBoreAttributes_getattr,   \
                  PyWellBoreAttributes_setattr,   \
                  WellBoreAttributes_str,         \
                  WellBoreAttributes_Purpose,     \
                  WellBoreAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
WellBoreAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &WellBoreAttributesType
         || Py_TYPE(other) != &WellBoreAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    WellBoreAttributes *a = ((WellBoreAttributesObject *)self)->data;
    WellBoreAttributes *b = ((WellBoreAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static WellBoreAttributes *defaultAtts = 0;
static WellBoreAttributes *currentAtts = 0;

static PyObject *
NewWellBoreAttributes(int useCurrent)
{
    WellBoreAttributesObject *newObject;
    newObject = PyObject_NEW(WellBoreAttributesObject, &WellBoreAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new WellBoreAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new WellBoreAttributes(*defaultAtts);
    else
        newObject->data = new WellBoreAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapWellBoreAttributes(const WellBoreAttributes *attr)
{
    WellBoreAttributesObject *newObject;
    newObject = PyObject_NEW(WellBoreAttributesObject, &WellBoreAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (WellBoreAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
WellBoreAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewWellBoreAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef WellBoreAttributesMethods[] = {
    {"WellBoreAttributes", WellBoreAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *WellBoreAttributesObserver = 0;

std::string
PyWellBoreAttributes_GetLogString()
{
    std::string s("WellBoreAtts = WellBoreAttributes()\n");
    if(currentAtts != 0)
        s += PyWellBoreAttributes_ToString(currentAtts, "WellBoreAtts.", true);
    return s;
}

static void
PyWellBoreAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("WellBoreAtts = WellBoreAttributes()\n");
        s += PyWellBoreAttributes_ToString(currentAtts, "WellBoreAtts.", true);
        cb(s);
    }
}

void
PyWellBoreAttributes_StartUp(WellBoreAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyWellBoreAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(WellBoreAttributesObserver == 0)
    {
        WellBoreAttributesObserver = new ObserverToCallback(subj,
            PyWellBoreAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyWellBoreAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete WellBoreAttributesObserver;
    WellBoreAttributesObserver = 0;
}

PyMethodDef *
PyWellBoreAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return WellBoreAttributesMethods;
}

bool
PyWellBoreAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &WellBoreAttributesType);
}

WellBoreAttributes *
PyWellBoreAttributes_FromPyObject(PyObject *obj)
{
    WellBoreAttributesObject *obj2 = (WellBoreAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyWellBoreAttributes_New()
{
    return NewWellBoreAttributes(0);
}

PyObject *
PyWellBoreAttributes_Wrap(const WellBoreAttributes *attr)
{
    return WrapWellBoreAttributes(attr);
}

void
PyWellBoreAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    WellBoreAttributesObject *obj2 = (WellBoreAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyWellBoreAttributes_SetDefaults(const WellBoreAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new WellBoreAttributes(*atts);
}

